<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" label-width="98px" ref="queryForm" size="small"
             v-show="showSearch">
      <el-form-item label="订单编号" prop="code">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入订单编号" v-model="queryParams.code"/>
      </el-form-item>
      <el-form-item label="业务员" prop="master">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入业务员" v-model="queryParams.master"/>
      </el-form-item>
      <el-form-item label="客户名称" prop="customName">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入客户名称" v-model="queryParams.customName"/>
      </el-form-item>

      <el-form-item label="是否回款完毕" prop="fundCallback">
        <el-select clearable placeholder="是否回款完毕" style="width: 200px" v-model="queryParams.fundCallback">
          <el-option :key="dict.value"
                     :label="dict.label" :value="dict.value" v-for="dict in dict.type.yes_no"/>
        </el-select>
        <!--        <el-input v-model="queryParams.fundCallback" placeholder="请输入是否回款完毕" clearable @keyup.enter.native="handleQuery"/>-->
      </el-form-item>
      <el-form-item label="所属年度" prop="year">
        <el-date-picker clearable
                        placeholder="请选择所属年度"
                        type="year"
                        v-model="queryParams.year"
                        value-format="yyyy">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-button type="info" icon="el-icon-upload2" size="mini"
                 @click="showUploadDialog">导入</el-button>
      <el-col :span="1.5">
        <el-button @click="handleExport" icon="el-icon-download" plain size="mini"
                   type="warning" v-hasPermi="['develop:ProjectBaseInfo:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table :data="dataList" :max-height="tableMaxHeight" @selection-change="handleSelectionChange"
              v-loading="loading">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="订单编号" prop="code" width="200">
      <template slot-scope="scope">
        <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="handleUpdateDetail(scope.row)"
                  style="color: #00afff;cursor:pointer;">{{scope.row.code}}</span>
        </el-tooltip>
      </template>
    </el-table-column>
      <el-table-column align="center" label="订单名称" prop="name" width="200">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="handleUpdateDetail(scope.row)"
                  style="color: #00afff;cursor:pointer;">{{scope.row.name}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" label="业务员" prop="master"/>
      <!--      <el-table-column label="客户" align="center" prop="customId"/>-->
      <!--      <el-table-column align="center" label="客户名称" prop="customName" width="200"/>-->
      <!--      <el-table-column label="标识" align="center" prop="companyName"/>-->
      <!--<el-table-column align="center" label="合同签订日期" prop="contractDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column align="center" label="订单金额" prop="contractMoney"/>
      <!--      <el-table-column align="center" label="审计后金额" prop="auditMoney"/>-->
      <!--<el-table-column label="验收日期" align="center" prop="checkDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <!--<el-table-column align="center" label="是否验收" prop="checkState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.checkState"/>
        </template>
      </el-table-column>-->
      <!--      <el-table-column align="center" label="质保金额" prop="retentionMoney"/>-->
      <!--      <el-table-column align="center" label="费用金额" prop="feeMoney"/>-->
      <el-table-column align="center" label="剩余开票金额" prop="taxRemain"/>
      <el-table-column align="center" label="剩余回款金额" prop="remainMoney"/>
      <el-table-column align="center" label="开票状态" prop="taxStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tax_status" :value="scope.row.taxStatus"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="质保金到期日期" align="center" prop="retentionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.retentionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column align="center" label="回款状态" prop="fundCallback">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fund_status" :value="scope.row.fundCallback"/>
        </template>
      </el-table-column>
      <!--      <el-table-column label="备注信息" align="center" prop="infomation"/>-->
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="300">
        <template slot-scope="scope">
          <!--<el-button size="mini" type="text" icon="el-icon-info"
                     @click="handleUpdateDetail(scope.row)" v-hasPermi="['develop:ProjectBaseInfo:edit']">详情
          </el-button>-->
          <!--<el-button @click="handleAddFeeInfo(scope.row)" icon="el-icon-plus" size="mini" type="text">
            研发经费
          </el-button>-->
          <!--<el-button @click="handleAddInvoiceInfo(scope.row)" icon="el-icon-plus" size="mini" type="text">
            开具发票
          </el-button>-->
          <!--<el-button @click="handleAddFundBackInfo(scope.row, '1')" icon="el-icon-plus" size="mini" type="text">
            计划回款信息
          </el-button>-->
          <!--<el-button size="mini" type="text" icon="el-icon-plus" @click="handleAddFundBackInfo(scope.row, '2')">
            实际回款信息
          </el-button>-->
          <!--<el-button @click="fapiaoHX(scope.row, '2')" icon="el-icon-plus" size="mini" type="text">
            发票核销
          </el-button>-->
          <el-button @click="handleChoseGoods(scope.row)" v-if="scope.row.status==2" icon="el-icon-plus" size="mini" type="text">
            产品请购
          </el-button>
          <el-button @click="handleChoseOther(scope.row)" icon="el-icon-plus" size="mini" type="text">
            其他请购
          </el-button>
          <el-button @click="lookGoods(scope.row)"  icon="el-icon-view" size="mini" type="text">
            请购明细
          </el-button>
          <el-popconfirm :title="`确认要发起请购该订单吗？`" @confirm="submitProjectScalaDo(scope.row)"
                         style="margin-left: 10px;"  v-if="scope.row.status==2 || scope.row.status==22">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete">发起采购
            </el-button>
          </el-popconfirm>

          <!--<el-button type="text" icon="el-icon-download"
                     @click="exportExcel(scope.row)">导出
          </el-button>-->
          <!--<el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:ProjectBaseInfo:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除 `+scope.row.id+` 数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
            </el-button>
          </el-popconfirm>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
                @pagination="getList" v-show="total>0"/>

    <pleaseBuy-form-goods @ok="getList" ref="formGoods"></pleaseBuy-form-goods>
    <pleaseBuy-look-goods @ok="getList" ref="lookGoodsForm"></pleaseBuy-look-goods>
    <goods-orderin-chose @ok="getList" ref="formChoseOther"></goods-orderin-chose>
  </div>
</template>

<script>
    import {deleteAction, getAction} from '@/api/manage'
    import Treeselect from "@riophae/vue-treeselect";
    import PleaseBuyLookGoods from './prjForGoodsIn/PleaseBuyLookGoods';
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    import {treeselect} from "@/api/system/dept";
    import PleaseBuyFormGoods from "./prjForGoodsIn/PleaseBuyFormGoods";
    import GoodsOrderinChose from "@/views/develop/pleaseBuy/prjForGoodsIn/GoodsBuyChose";

    export default {
        name: "PleaseBuyOrderList2",
        dicts: ['yes_no', 'fund_callback', 'fund_status', 'tax_status'],
        components: {
            PleaseBuyLookGoods,
            PleaseBuyFormGoods,
            Treeselect,
            GoodsOrderinChose
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 订单基础信息管理表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    yearStr: null,
                    pageNum: 1,
                    pageSize: 20,
                    name: null,
                    status:"2",
                    master: null,
                    customId: null,
                    customName: null,
                    companyName: null,
                    contractDate: null,
                    contractMoney: null,
                    auditMoney: null,
                    checkDate: null,
                    checkState: null,
                    fundCallback: null,
                    infomation: null,
                    orderByColumn: "create_time",
                    isAsc: "desc",
                    params:{},
                },
                url: {
                    list: '/projectBaseInfo/projectBaseInfo/list',
                    remove: '/projectBaseInfo/projectBaseInfo/',
                    export: '/projectBaseInfo/projectBaseInfo/export',
                  submitProjectScalaDo: '/projectBaseInfo/projectBaseInfo/submitProjectScalaDo',
                },
                tableMaxHeight: window.innerHeight - 320,
                // 部门树选项
                deptOptions: [],
            };
        },
        created() {
            //this.initQuery();
            this.getList();
            //this.getTreeselect();
        },
        methods: {
          handleChoseOther(row) {
            this.$refs.formChoseOther.chose(row.id, "2");
          },
          submitProjectScalaDo(row){
            getAction(this.url.submitProjectScalaDo, {id:row.id,status:"4"}).then(response => {
              /*this.refreshPageData();
              this.$modal.msgSuccess("提交成功!");
              this.open = false;
              this.handleQuery();*/
              this.getList();
              this.$modal.msgSuccess("提交成功!");
            }).catch(() => {
            });
          },
            lookGoods(row){
              this.$refs.lookGoodsForm.handleUpdate(row);
            },
            initQuery() {
                let that = this;
                if (that.$route.query.dataFlag) {
                    that.queryParams.params.dataFlag = that.$route.query.dataFlag;
                }
            },
            /** 查询部门下拉树结构 */
            getTreeselect() {
                treeselect().then(response => {
                    this.deptOptions = response.data;
                });
            },
            exportExcel(id) {
                let that = this;
                that.loading = false;
                that.$confirm('是否确认导出详细信息信息?', "确认", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    downloadFile('/projectBaseInfo/projectBaseInfo/exportExcel', id);
                });
            },
            fapiaoHX(row, type) {
                let that = this;
                that.$refs.InvoiceInfoListDialog.showAllInvoices(row);
            },
            handleAddFeeInfo(row) {
                let that = this;
                // that.$refs.ProjectFeeInfoFormForPrj.handleAddNew(row);
                that.$refs.ProjectBaseInfoFormGoodsFee.handleUpdate(row);
            },
            /*handleAddFundBackInfo(row, type) {
                let that = this;
                row.type = type;
                that.$refs.ProjectFundBackFormForPrj.handleAddNew(row);
            },*/
            /*handleAddFundBackInfoActual(row, type){
                let that = this;
                row.type = type;
                that.$refs.ProjectFundBackFormForPrj.handleAddNew(row);
            },*/
            handleAddInvoiceInfo(row) {
                let that = this;
                that.$refs.ProjectInvoiceInfoFormForPrj.handleAddNew(row);
            },

            handleUpdateDetail(row) {
                this.$refs.ProjectBaseInfoFormForPrj.handleUpdateDetail(row);
            },
            /** 查询项目基础信息管理列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            handleChoseGoods(row) {
                this.$refs.formGoods.handleUpdate(row);
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {
                });
            },

          handleFileSuccess(response, file, fileList) {
            this.$refs.uploadDialog.open = false;
            this.$refs.uploadDialog.isUploading = false;
            if (response.data.code == "200") {
              this.$alert("导入数据：" + response.data.num + "条！更新数据：" +response.data.numupdate+"条！"+ response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
            } else {
              this.$alert("导入数据：" + response.data.num + "条！更新数据：" +response.data.numupdate+"条！"+ response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
            }
            this.getList();
          },

          showUploadDialog(){
            this.$refs.uploadDialog.title = "信息导入";
            this.$refs.uploadDialog.tmplName = "订单信息模板.xlsx";
            this.$refs.uploadDialog.fileName = "订单信息.xlsx";
            this.$refs.uploadDialog.uploadUrl = "/projectBaseInfo/projectBaseInfo/importData";
            this.$refs.uploadDialog.show();
          },
            /** 导出按钮操作 */
            handleExport() {
                let that = this;
                that.loading = false;
                that.$confirm('是否确认导出项目信息表?', "确认", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    downloadFile('/projectBaseInfo/projectBaseInfo/exportBaseInfo', that.queryParams);
                });
            },
        }
    };
</script>
